package univer.oko.database.rmi.impl;

import univer.oko.Error;

import java.util.Vector;

/**
 * @author Eduard Dudar
 *         Date: 20.11.2005
 *         Time: 13:09:53
 */
public class EducationFormImpl extends ImplHelper {
    public EducationFormImpl(RMIImpl rmi) {
        super(rmi);
    }

    public int addEducationForm(String str) {
        if (this.isOccurs("SELECT ID_EducForm FROM Education_Form WHERE EducForm_Name='" + str + "'")) {
            return univer.oko.Error.REPEAT;
        }

        int count = this.getIntValue("SELECT MAX(ID_EducForm) FROM Education_Form") + 1;
        this.executeUpdate("INSERT INTO Education_Form VALUES(" + count + ",'" + str + "')");
        this.commit();
        return Error.ALRIGHT;
    }

    public Vector getEducationForms() {
        return this.getVectorValue("SELECT EducForm_Name FROM Education_Form ORDER BY EducForm_Name");
    }

    public int deleteEducationForm(String str) {
        boolean isOccurs = this.isOccurs(
                "SELECT Education_Form.EducForm_Name FROM Education_Form, Student " +
                        "WHERE Student.Ref_EducForm = Education_Form.ID_EducForm " +
                        "AND Education_Form.EducForm_Name = '" + str + "'");
        if (isOccurs) {
            return Error.IN_USE;
        }

        this.executeUpdate("DELETE FROM Education_Form WHERE EducForm_Name = '" + str + "'");
        this.commit();
        return Error.ALRIGHT;
    }

    public Integer getEducationFormID(String str) {
        return this.getIntValue("SELECT ID_EducForm FROM Education_Form WHERE EducForm_Name = '" + str + "'");
    }

    public String getEducationFormName(int id) {
        return this.getStringValue("SELECT EducForm_Name FROM Education_Form WHERE ID_EducForm = " + id);
    }
}
